﻿
--#include "data\config\guide\paysales.lua" once --充值促销系统
--#include "data\functions\Systems\PaySalesSystem\Common.lua" once

--#include "data\functions\Systems\PaySalesSystem\SurpriseRet.lua" once --惊喜回馈

--#include "data\functions\Systems\Platforms\7KPlatform.lua" once
--#include "data\functions\Systems\Platforms\BtyouPlatform.lua" once
--#include "data\functions\player.lua" once
--#include "data\functions\Vip\VipCommon.lua" once
--#include "data\functions\recharge\FirstRecharge.lua" once  --首冲
--#include "data\functions\recharge\FashionRecharge.lua" once --时装首充
--#include "data\functions\recharge\HeroGodWeaponRecharge.lua" once --英雄神兵累充
--#include "data\functions\Activity\OpenServer\OpenServerDailyRecharge.lua" once  开服每日充值

--#include "data\functions\Activity\BackStageActivity\DailyRecharge.lua"   once         -- 每日充值
--#include "data\functions\Activity\BackStageActivity\TimeLimitShopping.lua"   once         -- 限时商品
--#include "data\functions\Activity\BackStageActivity\TotalRecharge.lua"   once         -- 累计充值
--#include "data\functions\Activity\BackStageActivity\TotalCost.lua"   once         -- 累计消费
----#include "data\functions\welfare\InvestPlan.lua" once          --投资计划
--#include "data\functions\Activity\OpenServer\OpenServerTotalRecharge.lua" once
--#include "data\functions\Activity\OpenServer\OpenServerRechargeRank.lua" once
--#include "data\functions\Activity\OpenServer\OpenServerConsumeRank.lua" once
--#include "data\functions\Activity\OpenServer\OpenServerFirstRecharge.lua" once
--#include "data\functions\Activity\OpenServer\OpenServerContinuousRecharge.lua" once
--#include "data\functions\Activity\OpenServer\OpenServerPKRank.lua" once
--#include "data\functions\Activity\CombineServer\CombineServerHandle.lua" once			--合服活动

--#include "data\functions\Activity\Operation\operation.lua" once   --运营活动

--[[提取元宝
此时PROP_ACTOR_DRAW_YB_COUNT属性已经是最新的充值元宝数量
]]
EventCallDispatcher.WithDrawYuanBaoHandler = function (sysarg, args)
	local nYuanBao = args[1]	--提取元宝数目
	OnVipActorChargeYuanBao( sysarg, nYuanBao )			--VIP系统充值相关（2017.1）

	if nYuanBao > 0 then
		OpenServerDailyRechargeWithDrawYuanBao(sysarg, nYuanBao) --开服每日充值 这个必须必首冲前面

		UpdateFirstRechargeGetState(sysarg)						--首冲

		OnFashionRechargeWithDrawYuanBao(sysarg, nYuanBao)		--时装首充

		OnHeroGodWeaponRechargeWithDrawYuanBao(sysarg, nYuanBao)--神兵累充

		DailyRechargeWithDrawYuanBao(sysarg, nYuanBao)			--每日充值

		TimeLimitShoppingWithDrawYuanBao(sysarg, nYuanBao)		--限时商品

		TotalRechargeWithDrawYuanBao(sysarg, nYuanBao)			--累计充值

		--InvestPlanWithDrawYuanbaoHandler(sysarg, nYuanBao)		--投资计划

		operationWithDrawYuanbaoHandler(sysarg, nYuanBao)		--运营活动

		OpenServerTotalRechargeWithDrawYuanbao(sysarg, nYuanBao)	--开服累计充值

		OpenServerDailyTotalRechargeWithDrawYuanbao(sysarg, nYuanBao)	--开服每日累计充值

		OpenServerRechargeRankWithDrawYuanbao(sysarg, nYuanBao)	--开服充值排行

		CombineServerRechargeRankWithDrawYuanbao(sysarg, nYuanBao)	--合服充值排行

		OpenServerFirstRechargeWithDrawYuanbao(sysarg, nYuanBao)	--开服前几次充值

		OpenServerContinuousRechargeWithDrawYuanBao(sysarg, nYuanBao)	--开服连续充值

		OnSuperVipWithDrawYuanBao(sysarg, nYuanBao) --至尊特权

		--记录每日充值元宝（如要使用这些数据，方法加在后面）
		local dailyCharge = Actor.getDailyChargeYuanBao( sysarg )
	Actor.setDailyChargeYuanBao( sysarg, dailyCharge + nYuanBao )

		local dailyChargeSingle = Actor.getDailyChargeSingleYuanBao( sysarg )
		if nYuanBao > dailyChargeSingle then 		--最大单笔充值
			Actor.setDailyChargeSingleYuanBao( sysarg, nYuanBao )
		end

		SendCommonDailyChargeAndCounsume( sysarg )

		local progress = Actor.getIntProperty(sysarg , PROP_ACTOR_DRAW_YB_COUNT)
		local vipGrade = Actor.getVipGrade(sysarg)
		OpenServerPKRankTriggleEvent(sysarg, enOpenServerRank_VIP, vipGrade, progress)
	end
end

--消费元宝，该函数可热更(@rsf)
EventCallDispatcher.ConsumeYuanBaoHandler = function (sysarg, args)
	local nYuanBao = args[1]	--消费元宝数目
	local nLogId = args[2] --日志ID
		
	local var = Actor.getStaticVar(sysarg)
	
	--当天消耗元宝数
	local dayConsumeYB = var.dayConsumeYB
	if dayConsumeYB == nil then
		dayConsumeYB = nYuanBao
	else
		dayConsumeYB = dayConsumeYB + nYuanBao
	end
	
	var.dayConsumeYB = dayConsumeYB

	OnRankingConsumeYbEvent(sysarg, dayConsumeYB)

	TotalCostConsumeYuanBao(sysarg, nYuanBao)				--累计消费

	OpenServerConsumeRankConsumeYuanBao(sysarg, nYuanBao)	--开服消费排行

	CombineServerConsumeRankConsumeYuanBao(sysarg, nYuanBao)	--合服消费排行

	operationConsumeYuanbaoHandler(sysarg, nYuanBao)		--运营活动

	OnCarnivalConsumeYuanbao(sysarg, nYuanBao)	--狂欢活动
	--记录每日消费元宝（如要使用这些数据，方法加在后面）
	local dailyConsume = Actor.getDailyConsumeYuanBao( sysarg )
	Actor.setDailyConsumeYuanBao( sysarg, dailyConsume + nYuanBao )
	SendCommonDailyChargeAndCounsume( sysarg )
end



function GetPeyYuanBaoHandlerEx(sysarg, args)
	local nYuanBao = args[1]	--获取充值元宝数目
	local var = Actor.getStaticVar(sysarg)
	if not var.days then var.days = {} end
	
	--获取玩家私人变量
	local peyNum = var.days.PeyNum			--每天充值数量
	if not peyNum then peyNum = 0 end
	
	local peyflag = var.days.PeyFlag		--每天领取的标识
	if not peyflag then peyflag = 0 end

	local RechargeIntegral = var.RechInt		-- 充值积分
	if not RechargeIntegral then RechargeIntegral = 0 end
	
	local YuanBao = var.nYuanBao						-- 累计充值的元宝数
	if not YuanBao then YuanBao = 0 end
	
	var.RechInt = RechargeIntegral + nYuanBao		-- 增加积分

	--获取上次领取每次充值礼包时间和本次登录时间
	local loginTime = System.getCurrMiniTime()
	local lastPeyTime = var.lastPeyTime
	if not lastPeyTime then
		var.lastPeyTime = System.getCurrMiniTime()
	end

	--检查是否同一天
	if System.isSameDay(loginTime, lastPeyTime) == false then
		var.days.PeyFlag = nil
		var.days.PeyNum = nYuanBao			--如果不是同一天，则清空上次的领取标识和充值数量
	else
		var.days.PeyNum = peyNum + nYuanBao
	end
	
	var.lastPeyTime = System.getCurrMiniTime()
	--下发今天充值的元宝数
	SendTodayPay(sysarg);
end


--充值赠送神器 (没用了)
EventCallDispatcher.GetRecharge = function (sysarg,args)
	--判断角色是否充值了
	if 0 >= Actor.getUIntProperty(sysarg, PROP_ACTOR_DRAW_YB_COUNT) then
		--您尚未充值，无法领取奖励.. (4)
		Actor.sendTipmsg(sysarg, Lang.Activity.czzs001, ttFlyTip)
		return
	end

	--判断是否已经领取
	local var = Actor.getStaticVar(sysarg)
	local getFlag = var.getFlag
	if not getFlag then
		var.getFlag = 0
	else
		if 1 == getFlag then
			--已经领取了,--关闭图标
			local pack = DataPack.allocPacket(sysarg, 26, 67)
			DataPack.writeByte(pack, 1)
			DataPack.flush(pack)
			return
		end
	end
	
	--检查背包空格子数量
	if 0 >= Item.getBagEmptyGridCount(sysarg) then
		--请至少整理出一个背包空格来容纳奖励..(4)
		Actor.sendTipmsg(sysarg, Lang.Activity.czzs002, ttFlyTip)
		return
	end
	
	--要添加的道具ID
	local addItemID = 698
	--道具时间限制
	local itemTimeLimit = 43200
	
	--添加到背包
	if Actor.addItem(sysarg,addItemID,0,0,1,1,itemTimeLimit,"GetRecharge",954) >= 1 then
		--修改领取标志位
		var.getFlag = 1
		
		--关闭图标
		local pack = DataPack.allocPacket(sysarg, 26, 67)
		DataPack.writeByte(pack, 1)
		DataPack.flush(pack)
		
		--恭喜您成功领取了充值神器奖励!(256)
		Actor.sendTipmsg(sysarg, Lang.Activity.czzs003, ttFlyTip)
		--玩家XXXX成功领取了充值特别奖励,绝世神器XXXXX一把!(聊天框+2)
		System.broadcastTipmsg(string.format(Lang.ScriptTips.zf598,Actor.getName(sysarg),Item.getItemLinkMsg(addItemID)),ttScreenCenter+ ttChatWindow)		
	else
		print("Award Item Error , ItemId is 698,  ActorName = "..Actor.getName(sysarg))
	end
end

--下发今天充值的元宝数
function SendTodayPay(sysarg)
	local var = Actor.getStaticVar(sysarg)
	if not var.days then var.days = {} end
	local pay = var.days.PeyNum
	
	--0也要发，因为有可能是隔天
	if pay == nil then pay = 0 end
	
	local pack = DataPack.allocPacket(sysarg, LogicCmd.miscSys.sysId, LogicCmd.miscSys.sub.sSendTodayPay)
	DataPack.writeInt(pack, pay)
	DataPack.flush(pack)
end




EventCallDispatcher.registerEventCall(BaseTypes.ActorEventId.aeWithDrawYuanBao, EventCallDispatcher.WithDrawYuanBaoHandler)
EventCallDispatcher.registerEventCall(BaseTypes.ActorEventId.aeConsumeYbEvent, EventCallDispatcher.ConsumeYuanBaoHandler)

--EventCallDispatcher.registerEventCall(BaseTypes.ActorEventId.aeGetRecharge, EventCallDispatcher.GetRecharge)		--充值赠送神器